require 'net/http'
require "uri"

module Test
  BOUNDARY = "AaB03x"
  def downloadFile
    uri  = URI("http://localhost:8080/a/FidelityMain.apk")
    Net::HTTP.start(uri.host, uri.port) do |http|
      request = Net::HTTP::Get.new uri.request_uri
      http.request request do |response|
        open 'c:\\test\\large_file.apk','wb' do |io|
          response.read_body do |chunk|
            io.write chunk
          end
        end
        attachment = Attachment.new(:uploaded_data => LocalFile.new(tempfile.path))
        attachement.save
      end
    end
  end

  def getFile

    uri = URI.parse("http://localhost:8080/a/FidelityMain.apk")
    file = "C://test//FidelityMain.apk"

    post_body = []
    post_body << "--#{BOUNDARY}rn"
    post_body << "Content-Disposition: form-data; name=\"datafile\"; filename=\"FidelityMain.apk\"rn"
    post_body << "Content-Type: text/plainrn"
    post_body << "rn"
    post_body << "rn--#{BOUNDARY}--rn"

    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Post.new(uri.request_uri)
    request.body = post_body.join
    request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"

   response =  http.request(request)
     open("ttt.apk ","wb") do |f|
     f.write response.body
     f.close
   end
   
   
  end
end

